<div class="middle">
  <div class="middle-header">
    <div class="container-fluid">
      <breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
      <alerts alerts="alerts"></alerts>
      <div ng-if="!loaded" class="mar-top-xl">Loading...</div>
      <div ng-if="build">
        <h1 class="contains-actions">
          <div class="pull-right dropdown" ng-hide="!('builds' | canIDoAny)">
            <!-- Primary Actions -->
            <button class="btn btn-default hidden-xs"
                    ng-click="cancelBuild()"
                    ng-if="!build.metadata.deletionTimestamp && (build | isIncompleteBuild) && (buildsVersion | canI : 'update')">Cancel Build</button>
            <button class="btn btn-default hidden-xs"
                    ng-click="cloneBuild()"
                    ng-hide="build.metadata.deletionTimestamp || (build | isIncompleteBuild) || !('builds/clone' | canI : 'create') || (build | isBinaryBuild)"
                    ng-disabled="!canBuild">Rebuild</button>

            <!-- Secondary Actions -->
            <button type="button" class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs" data-toggle="dropdown">
              Actions
              <span class="caret" aria-hidden="true"></span>
            </button>
            <a href=""
               class="dropdown-toggle actions-dropdown-kebab visible-xs-inline"
               data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
            <ul class="dropdown-menu dropdown-menu-right actions action-button">
              <li ng-if="buildConfigsVersion | canI : 'update'">
                <a ng-href="{{buildConfig | editResourceURL}}" role="button">
                  <span ng-if="!(buildConfig | isJenkinsPipelineStrategy)">
                    Edit Configuration
                  </span>
                  <span ng-if="buildConfig | isJenkinsPipelineStrategy">
                    Edit Pipeline
                  </span>
                </a>
              </li>
              <li class="divider" ng-if="buildConfigsVersion | canI : 'update'"></li>
              <li ng-if="!build.metadata.deletionTimestamp && (build | isIncompleteBuild) && (buildsVersion | canI : 'update')"
                  class="visible-xs-inline">
                <a href=""
                   role="button"
                   ng-click="cancelBuild()">Cancel Build</a>
              </li>
              <li class="visible-xs-inline"
                  ng-class="{ disabled: !canBuild }"
                  ng-hide="build.metadata.deletionTimestamp || (build | isIncompleteBuild) || !('builds/clone' | canI : 'create') || (build | isBinaryBuild)">
                <a href=""
                   role="button"
                   ng-click="cloneBuild()"
                   ng-attr-aria-disabled="{{canBuild ? undefined : 'true'}}"
                   ng-class="{ 'disabled-link': !canBuild }">Rebuild</a>
              </li>
              <li ng-if="(buildsVersion | canI : 'update')">
                <a ng-href="{{build | editYamlURL}}" role="button">Edit YAML</a>
              </li>
              <li ng-if="(buildsVersion | canI : 'delete')">
                <delete-link
                  kind="Build"
                  resource-name="{{build.metadata.name}}"
                  project-name="{{build.metadata.namespace}}"
                  alerts="alerts"
                  redirect-url="{{build | configURLForResource}}">
                </delete-link>
              </li>
            </ul>
          </div>
          {{build.metadata.name}}
          <span class="pficon pficon-warning-triangle-o"
                ng-if="buildConfigPaused || buildConfigDeleted"
                aria-hidden="true"
                data-toggle="tooltip"
                data-original-title="{{buildConfigDeleted ? 'The build configuration for this build no longer exists.' : 'Building from build configuration ' + buildConfig.metadata.name + ' has been paused.'}}">
          </span>
          <small class="meta">created <span am-time-ago="build.metadata.creationTimestamp"></span></small>
        </h1>
        <labels ng-if="buildConfigName" labels="build.metadata.labels" clickable="true" kind="builds" title-kind="builds for build config {{buildConfigName}}" project-name="{{build.metadata.namespace}}" limit="3" navigate-url="project/{{build.metadata.namespace}}/browse/builds/{{buildConfigName}}"></labels>
        <labels ng-if="!buildConfigName" labels="build.metadata.labels" limit="3"></labels>
      </div>
    </div>
  </div><!-- /middle-header-->
  <div class="middle-content" persist-tab-state>
    <div class="container-fluid">
      <div class="row" ng-if="build">
        <div class="col-md-12">

            <uib-tabset>
              <uib-tab active="selectedTab.details">
                <uib-tab-heading>Details</uib-tab-heading>
                <build-pipeline build="build" ng-if="build | isJenkinsPipelineStrategy"></build-pipeline>
                <ng-include src=" 'views/browse/_build-details.html' "></ng-include>
              </uib-tab>

              <uib-tab heading="Environment" active="selectedTab.environment" ng-if="!(build | isJenkinsPipelineStrategy)">
                <uib-tab-heading>Environment</uib-tab-heading>
                <h3>Environment Variables</h3>
                <p ng-if="buildConfigsVersion | canI : 'update'">
                  <span class="pficon pficon-info" aria-hidden="true"></span>
                  Environment variables can be edited on the <a ng-href="{{build | configURLForResource}}?tab=environment">build configuration</a>.
                </p>
                <key-value-editor
                  ng-if="(build | buildStrategy).env | size"
                  entries="(build | buildStrategy).env"
                  key-placeholder="Name"
                  value-placeholder="Value"
                  cannot-add
                  cannot-delete
                  cannot-sort
                  is-readonly
                  show-header
                  class="mar-bottom-xl block"></key-value-editor>
                <p ng-if="!(build | buildStrategy).env"><em>The build strategy had no environment variables defined.</em></p>
              </uib-tab>

              <uib-tab active="selectedTab.logs" ng-if="!(build | isJenkinsPipelineStrategy) && ('builds/log' | canI : 'get')">
                <uib-tab-heading>Logs</uib-tab-heading>
                <log-viewer
                  ng-if="selectedTab.logs"
                  follow-affix-top="390"
                  object="build"
                  context="projectContext"
                  options="logOptions"
                  empty="logEmpty"
                  run="logCanRun">

                  <label>Status:</label>
                  <status-icon status="build.status.phase"></status-icon>
                  <span class="space-after">{{build.status.phase}}</span>

                  <div ng-if="build.status.startTimestamp && !logEmpty" class="log-timestamps">
                    Log from {{build.status.startTimestamp  | date : 'medium'}}
                    <span ng-if="build.status.completionTimestamp">
                      to {{build.status.completionTimestamp  | date : 'medium'}}
                    </span>
                  </div>

                </log-viewer>
              </uib-tab>
              <uib-tab active="selectedTab.events" ng-if="('events' | canI : 'watch')">
                <uib-tab-heading>Events</uib-tab-heading>
                <events api-objects="eventObjects" project-context="projectContext" ng-if="selectedTab.events"></events>
              </uib-tab>
            </uib-tabset>

        </div><!-- /col-* -->
      </div>
    </div>
  </div><!-- /middle-content -->
</div>
